home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
6_11.lha
/
6_11
/
6_11_c2.c
< prev
next >
Wrap
Text File
|
1993-08-08
|
912b
|
47 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
*
create an arbint from a (unsigned) long
/
include <arbint.h>
onst arbperlong = sizeof(long) / sizeof(ARB_type);
rbint::arbint(long n) // arbint x = 36L;
// allocate data area
p = new arep;
p->refcnt = 1;
p->length = arbperlong;
p->value = new ARB_type[arbperlong];
// assign the new value
for (int i = arbperlong - 1; i >= 0; i--)
{
p->value[i] = n % ARB_base;
n /= ARB_base;
}
rbint::arbint(unsigned long n) // arbint x = 3UL;
int nlen = arbperlong;
if ((long) n < 0)
nlen++;
// allocate data area
p = new arep;
p->refcnt = 1;
p->length = nlen;
p->value = new ARB_type[nlen];
// assign the new value
for (int i = nlen - 1; i >= 0; i--)
{
p->value[i] = n % ARB_base;
n /= ARB_base;
}